package com.to8to.kitt.zk;

public class ZkLock{
	private String fold;
	private String prefix;
	private String lockId = "";
	
	public ZkLock(String fold, String prefix)
	{
		this.fold = fold;
		this.prefix = prefix;
	}
	
	public String getFold() {
		return fold;
	}
	
	public boolean isNull()
	{
		return lockId.equals("");
	}

	public String getFullPath()
	{
		return fold + "/" + prefix + "-" + lockId;
	}
	public String getFullPrefix()
	{
		return fold + "/" + prefix + "-";	
	}
	public String getLocalName()
	{
		return prefix + "-" + lockId;
	}
	public void setLockId(String lockId) {
		this.lockId = lockId;
	}

	public ZkLock(String fullPath)
	{
		int index = fullPath.lastIndexOf("/");
		if(index != -1)
		{
			fold = fullPath.substring(0, index);
			String tmp = fullPath.substring( index + 1);
			
			index = tmp.lastIndexOf("-");
			if(index != -1)
				lockId = tmp.substring(index + 1);
		}
	}
	
	public String getPrefix() {
		return prefix;
	}

	public String getLockId()
	{
		return lockId;
	}
}
